namespace PickGold.Charting
{
    using System;
    using System.Collections;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Globalization;

    internal class HotRegionsList : IDisposable
    {
        private CommonElements _common;
        private ProcessMode _processChartMode = ProcessMode.Paint;
        private ArrayList _regionList = new ArrayList();

        internal HotRegionsList(CommonElements common)
        {
            this._common = common;
        }

        internal void AddHotRegion(GraphicsPath path, bool relativePath, ChartElementType type, object selectedObject)
        {
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.SelectedObject = selectedObject;
                region.Type = type;
                region.Path = (GraphicsPath) path.Clone();
                region.BoundingRectangle = path.GetBounds();
                region.RelativeCoordinates = relativePath;
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(RectangleF rectArea, object selectedObject, ChartElementType type, bool relativeCoordinates)
        {
            this.AddHotRegion(rectArea, selectedObject, type, relativeCoordinates, false);
        }

        public void AddHotRegion(RectangleF rectSize, DataPoint point, string seriesName, int pointIndex)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((point.ToolTip.Length > 0) || (point.Url.Length > 0)) || ((point.MapAreaAttributes.Length > 0) || (point.PostBackValue.Length > 0))))
            {
                MapArea item = new MapArea(point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Url), point.ReplaceKeywords(point.MapAreaAttributes), point.ReplaceKeywords(point.PostBackValue), rectSize, point.Tag);
                item.IsCustom = false;
                this._common.ChartPicture.MapAreas.Insert(0, item);
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.BoundingRectangle = rectSize;
                region.SeriesName = seriesName;
                region.PointIndex = pointIndex;
                region.Type = ChartElementType.DataPoint;
                region.RelativeCoordinates = true;
                if ((point != null) && point.IsCustomPropertySet("OriginalPointIndex"))
                {
                    region.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture);
                }
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(RectangleF rectArea, object selectedObject, ChartElementType type, bool relativeCoordinates, bool insertAtBeginning)
        {
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.BoundingRectangle = rectArea;
                region.RelativeCoordinates = relativeCoordinates;
                region.Type = type;
                region.SelectedObject = selectedObject;
                if (insertAtBeginning)
                {
                    this._regionList.Insert(this._regionList.Count - 1, region);
                }
                else
                {
                    this._regionList.Add(region);
                }
            }
        }

        internal void AddHotRegion(GraphicsPath path, bool relativePath, ChartGraphics graph, DataPoint point, string seriesName, int pointIndex)
        {
            if (path != null)
            {
                if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((point.ToolTip.Length > 0) || (point.Url.Length > 0)) || ((point.MapAreaAttributes.Length > 0) || (point.PostBackValue.Length > 0))))
                {
                    int count = this._common.ChartPicture.MapAreas.Count;
                    this._common.ChartPicture.MapAreas.InsertPath(0, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Url), point.ReplaceKeywords(point.MapAreaAttributes), point.ReplaceKeywords(point.PostBackValue), path, !relativePath, graph);
                    for (int i = 0; i < (this._common.ChartPicture.MapAreas.Count - count); i++)
                    {
                        this._common.ChartPicture.MapAreas[i].Tag = point.Tag;
                    }
                }
                if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
                {
                    HotRegion region = new HotRegion();
                    region.SeriesName = seriesName;
                    region.PointIndex = pointIndex;
                    region.Type = ChartElementType.DataPoint;
                    region.Path = (GraphicsPath) path.Clone();
                    region.BoundingRectangle = path.GetBounds();
                    region.RelativeCoordinates = relativePath;
                    if ((point != null) && point.IsCustomPropertySet("OriginalPointIndex"))
                    {
                        region.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture);
                    }
                    this._regionList.Add(region);
                }
            }
        }

        internal void AddHotRegion(GraphicsPath path, bool relativePath, float[] coord, DataPoint point, string seriesName, int pointIndex)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((point.ToolTip.Length > 0) || (point.Url.Length > 0)) || ((point.MapAreaAttributes.Length > 0) || (point.PostBackValue.Length > 0))))
            {
                MapArea item = new MapArea(MapAreaShape.Polygon, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Url), point.ReplaceKeywords(point.MapAreaAttributes), point.ReplaceKeywords(point.PostBackValue), coord, point.Tag);
                item.IsCustom = false;
                this._common.ChartPicture.MapAreas.Insert(0, item);
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.SeriesName = seriesName;
                region.PointIndex = pointIndex;
                region.Type = ChartElementType.DataPoint;
                region.Path = (GraphicsPath) path.Clone();
                region.BoundingRectangle = path.GetBounds();
                region.RelativeCoordinates = relativePath;
                if ((point != null) && point.IsCustomPropertySet("OriginalPointIndex"))
                {
                    region.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture);
                }
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(int insertIndex, GraphicsPath path, bool relativePath, ChartGraphics graph, DataPoint point, string seriesName, int pointIndex)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((point.ToolTip.Length > 0) || (point.Url.Length > 0)) || ((point.MapAreaAttributes.Length > 0) || (point.PostBackValue.Length > 0))))
            {
                int count = this._common.ChartPicture.MapAreas.Count;
                this._common.ChartPicture.MapAreas.InsertPath(insertIndex, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Url), point.ReplaceKeywords(point.MapAreaAttributes), point.ReplaceKeywords(point.PostBackValue), path, !relativePath, graph);
                for (int i = insertIndex; i < (this._common.ChartPicture.MapAreas.Count - count); i++)
                {
                    this._common.ChartPicture.MapAreas[i].Tag = point.Tag;
                }
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.SeriesName = seriesName;
                region.PointIndex = pointIndex;
                region.Type = ChartElementType.DataPoint;
                region.Path = (GraphicsPath) path.Clone();
                region.BoundingRectangle = path.GetBounds();
                region.RelativeCoordinates = relativePath;
                if ((point != null) && point.IsCustomPropertySet("OriginalPointIndex"))
                {
                    region.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture);
                }
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(RectangleF rectArea, string toolTip, string hRef, string mapAreaAttributes, string postBackValue, object selectedObject, ChartElementType type, string series)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((toolTip.Length > 0) || (hRef.Length > 0)) || ((mapAreaAttributes.Length > 0) || (postBackValue.Length > 0))))
            {
                MapArea item = new MapArea(toolTip, hRef, mapAreaAttributes, postBackValue, rectArea, ((IChartMapArea) selectedObject).Tag);
                item.IsCustom = false;
                this._common.ChartPicture.MapAreas.Add(item);
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.BoundingRectangle = rectArea;
                region.RelativeCoordinates = true;
                region.Type = type;
                region.SelectedObject = selectedObject;
                if (!string.IsNullOrEmpty(series))
                {
                    region.SeriesName = series;
                }
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(int insertIndex, ChartGraphics graph, float x, float y, float radius, DataPoint point, string seriesName, int pointIndex)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((point.ToolTip.Length > 0) || (point.Url.Length > 0)) || ((point.MapAreaAttributes.Length > 0) || (point.PostBackValue.Length > 0))))
            {
                float[] coordinates = new float[] { x, y, radius };
                MapArea item = new MapArea(MapAreaShape.Circle, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Url), point.ReplaceKeywords(point.MapAreaAttributes), point.ReplaceKeywords(point.PostBackValue), coordinates, point.Tag);
                item.IsCustom = false;
                this._common.ChartPicture.MapAreas.Insert(insertIndex, item);
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                PointF absolutePoint = graph.GetAbsolutePoint(new PointF(x, y));
                SizeF absoluteSize = graph.GetAbsoluteSize(new SizeF(radius, radius));
                GraphicsPath path = new GraphicsPath();
                path.AddEllipse((float) (absolutePoint.X - absoluteSize.Width), (float) (absolutePoint.Y - absoluteSize.Width), (float) (2f * absoluteSize.Width), (float) (2f * absoluteSize.Width));
                region.BoundingRectangle = path.GetBounds();
                region.SeriesName = seriesName;
                region.Type = ChartElementType.DataPoint;
                region.PointIndex = pointIndex;
                region.Path = path;
                region.RelativeCoordinates = false;
                if ((point != null) && point.IsCustomPropertySet("OriginalPointIndex"))
                {
                    region.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture);
                }
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(RectangleF rectArea, string toolTip, string hRef, string mapAreaAttributes, string postBackValue, object selectedObject, object selectedSubObject, ChartElementType type, string series)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((toolTip.Length > 0) || (hRef.Length > 0)) || ((mapAreaAttributes.Length > 0) || (postBackValue.Length > 0))))
            {
                MapArea item = new MapArea(toolTip, hRef, mapAreaAttributes, postBackValue, rectArea, ((IChartMapArea) selectedObject).Tag);
                item.IsCustom = false;
                this._common.ChartPicture.MapAreas.Add(item);
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.BoundingRectangle = rectArea;
                region.RelativeCoordinates = true;
                region.Type = type;
                region.SelectedObject = selectedObject;
                region.SelectedSubObject = selectedSubObject;
                if (!string.IsNullOrEmpty(series))
                {
                    region.SeriesName = series;
                }
                this._regionList.Add(region);
            }
        }

        internal void AddHotRegion(ChartGraphics graph, GraphicsPath path, bool relativePath, string toolTip, string hRef, string mapAreaAttributes, string postBackValue, object selectedObject, ChartElementType type)
        {
            if ((((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps) && this._common.ChartPicture.IsMapEnabled) && (((toolTip.Length > 0) || (hRef.Length > 0)) || ((mapAreaAttributes.Length > 0) || (postBackValue.Length > 0))))
            {
                this._common.ChartPicture.MapAreas.InsertPath(0, toolTip, hRef, mapAreaAttributes, postBackValue, path, !relativePath, graph);
            }
            if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions)
            {
                HotRegion region = new HotRegion();
                region.Type = type;
                region.Path = (GraphicsPath) path.Clone();
                region.SelectedObject = selectedObject;
                region.BoundingRectangle = path.GetBounds();
                region.RelativeCoordinates = relativePath;
                this._regionList.Add(region);
            }
        }

        public void Clear()
        {
            foreach (HotRegion region in this._regionList)
            {
                region.Dispose();
            }
            this._regionList.Clear();
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing && (this._regionList != null))
            {
                foreach (HotRegion region in this._regionList)
                {
                    region.Dispose();
                }
                this._regionList.Clear();
            }
        }

        internal int FindInsertIndex()
        {
            int num = 0;
            foreach (MapArea area in this._common.ChartPicture.MapAreas)
            {
                if (!area.IsCustom)
                {
                    return num;
                }
                num++;
            }
            return num;
        }

        internal ArrayList List
        {
            get
            {
                return this._regionList;
            }
        }

        internal ProcessMode ProcessChartMode
        {
            get
            {
                return this._processChartMode;
            }
            set
            {
                this._processChartMode = value;
                if (this._common != null)
                {
                    this._common.processModePaint = (this._processChartMode & ProcessMode.Paint) == ProcessMode.Paint;
                    this._common.processModeRegions = ((this._processChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) || ((this._processChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps);
                }
            }
        }
    }
}

